﻿#region << 版 本 注 释 >>
/*----------------------------------------------------------------
 * 创建者：王明亮
 * 创建时间：2023/9/18 10:59:26
 * 版本：V1.0.0
 * 描述：
 *
 * ----------------------------------------------------------------
 * 修改人：
 * 时间：
 * 修改说明：
 *
 * 版本：V1.0.1
 *----------------------------------------------------------------*/
#endregion << 版 本 注 释 >>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace BaiduAIAuditClient.Log4
{
    /// <summary>
    /// Logger 日志帮助类
    /// </summary>
    public class Logger
    {
        protected static log4net.ILog _log = null;


        /// <summary>
        /// 打开日志
        /// </summary>
        public Logger()
        {
            if (_log == null)
            {
                //log4net.Config.XmlConfigurator.Configure(new System.IO.FileInfo(Path.Combine(System.AppDomain.CurrentDomain.SetupInformation.PrivateBinPath , "web.config")));
                log4net.Config.XmlConfigurator.Configure(new System.IO.FileInfo(System.AppDomain.CurrentDomain.BaseDirectory + "Configs/log4net.config"));
                _log = log4net.LogManager.GetLogger("BaiduAIAuditClient");

                //写日志头信息
                Info("*============================================================");
                Info("Subject:  BaiduAIAuditClient  Log File");
                Info("BeginTime: " + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss fff"));
                Info("=============================================================");
            }
        }

        public void Error(string message)
        {
            try
            {
                _log.Error(message);
            }
            catch
            { }
        }

        public void Error(string message, Exception ex)
        {
            try
            {
                _log.Error(message, ex);
            }
            catch
            { }
        }

        public void Error(string format, params object[] arg0)
        {
            try
            {
                _log.ErrorFormat(format, arg0);
            }
            catch
            { }
        }

        public void Info(string message)
        {
            try
            {
                _log.Info(message);
            }
            catch
            { }
        }

        public void Info(string format, params object[] arg0)
        {
            try
            {
                _log.InfoFormat(format, arg0);
            }
            catch
            { }
        }

        public void Warn(string message)
        {
            try
            {
                _log.Warn(message);
            }
            catch
            { }
        }

        public void Close()
        {
            try
            {
                Info("=============================================================");
                Info("EndTime:   " + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss fff"));
                Info("============================================================*");
            }
            catch
            { }
        }

        ~Logger()
        {
            Close();
        }
    }
}
